{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "37c23595",
   "metadata": {},
   "source": [
    " # 本周学习内容\n",
    " >1.有序的数据结构之列表\n",
    " \n",
    " >2.用户输入\n",
    " \n",
    " >3.关于格式化文本信息"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "0e287fc5",
   "metadata": {},
   "outputs": [],
   "source": [
    "网三_01_list  = \"Marry\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "3429c99b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "H,M,J,K\n"
     ]
    }
   ],
   "source": [
    "网三_name_list = \"H,M,J,K\"\n",
    "print(网三_name_list)\n",
    "(全部)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "d02089cb",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'M'"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "网三_name_list[2:3]\n",
    "（取1）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "5293a339",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "7"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(网三_name_list)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ea85782f",
   "metadata": {},
   "source": [
    "# 1.引入列表的概念\n",
    " * 注释：我们已经学了数值与字符，list可以放数值和字符，但是通常只能放同一个\n",
    " >总结一些通用有序方法\n",
    " >>1.取值：通过索引值取出对应内容\n",
    " >>2.切片：通过索引值区间取出对应的一些内容\n",
    " >>3.in 可以查看成员对象是否存在\n",
    " \n",
    " >列表的一些方法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "dc001cf3",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1, 2, 3, 4] <class 'list'>\n"
     ]
    }
   ],
   "source": [
    "a = [1,2,3,4]\n",
    "print(a,type(a))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "9f29680a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "H,M,J,K <class 'str'>\n"
     ]
    }
   ],
   "source": [
    "网三_name_list = \"H,M,J,K\"\n",
    "print(网三_name_list,type(网三_name_list))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "04900cc0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "','"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "网三_name_list[1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "8eff424b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "网三： H,M,J,K\n"
     ]
    }
   ],
   "source": [
    "网三_name_list = [\"H,M,J,K\"]\n",
    "for i in 网三_name_list:\n",
    "    print(\"网三：\",i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "6cda1104",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"M\" in 网三_name_list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "141edf0e",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "7d20dc75",
   "metadata": {},
   "source": [
    "# 2.2列表的方法(Function) —对列表数据进行操作\n",
    "> 1. 增\n",
    "> 2. 删\n",
    "> 3. 改\n",
    "> 4. 查"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 137,
   "id": "39e0fab3",
   "metadata": {},
   "outputs": [],
   "source": [
    "网三_name_list.append(\"田林凯\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 138,
   "id": "06cdfcb6",
   "metadata": {},
   "outputs": [],
   "source": [
    "网三_name_list = [\"小峰,小黄，小福，小鹏，小凯\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 139,
   "id": "f7acce2a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function insert:\n",
      "\n",
      "insert(index, object, /) method of builtins.list instance\n",
      "    Insert object before index.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(网三_name_list.insert)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 140,
   "id": "c62d8371",
   "metadata": {},
   "outputs": [],
   "source": [
    "网一_name_list.insert(1,\"小黄\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 141,
   "id": "7625e855",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['小峰,小黄，小福，小鹏，小凯']"
      ]
     },
     "execution_count": 141,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "网三_name_list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 145,
   "id": "a614c2b2",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function remove:\n",
      "\n",
      "remove(value, /) method of builtins.list instance\n",
      "    Remove first occurrence of value.\n",
      "    \n",
      "    Raises ValueError if the value is not present.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(网三_name_list.remove)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 151,
   "id": "f4163648",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['小峰,小黄，小福，小鹏，小凯']"
      ]
     },
     "execution_count": 151,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "网三_name_list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 152,
   "id": "7665d55e",
   "metadata": {},
   "outputs": [],
   "source": [
    "if \"小凯\"in 网三_name_list:\n",
    "    网三_name_list.remove(\"小凯\")\n",
    "    网三_name_list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 160,
   "id": "7828974a",
   "metadata": {},
   "outputs": [],
   "source": [
    "age_list = [18,19,18,19,17,20,20,18,19,16,17,20]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 161,
   "id": "f7a88483",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3"
      ]
     },
     "execution_count": 161,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "age_list.count(19)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 162,
   "id": "2b8590aa",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[18, 19, 18, 19, 17, 20, 20, 18, 19, 16, 17, 20]"
      ]
     },
     "execution_count": 162,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "age_list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 163,
   "id": "6da9526d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[18, 18, 17, 20, 20, 18, 16, 17, 20]"
      ]
     },
     "execution_count": 163,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 思路1： remove(value),先决条件，知道值出现的次数\n",
    "删除的数量 = age_list.count(19)\n",
    "for i in range(删除的数量):\n",
    "    if 19 in age_list:\n",
    "        age_list.remove(19)\n",
    "    age_list\n",
    "age_list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 165,
   "id": "365056b3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[18, 18, 17, 20, 20, 18, 16, 17, 20]"
      ]
     },
     "execution_count": 165,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 思路2：pop(index),先决条件，知道值出现的位置\n",
    "for i,v in  enumerate(age_list):\n",
    "    if v == 19:\n",
    "       print(i,v)\n",
    "       age_list.pop(i)\n",
    "age_list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1bd2c52e",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
